package com.work.module_base.view;


import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.work.module_base.R;


/**
 * author：WangZhan
 * data: 2017/2/3 10:04
 * version: 1.0.0
 * explain:自定义加载对话框
 */

public class LoadingDialog extends Dialog {
    private static final int CHANGE_TITLE_WHAT = 1;
    private static final int CHNAGE_TITLE_DELAYMILLIS = 300;
    private static final int MAX_SUFFIX_NUMBER = 3;
    private static final char SUFFIX = '.';
    private Context context;

    //    private ImageView iv_route;
    private TextView detail_tv;
    private TextView tv_point;
//    private RotateAnimation mAnim;


    public LoadingDialog(Context context) {
        super(context, R.style.MyDialogStyle);
        this.context = context;
        init();
    }


    public LoadingDialog(Context context, boolean isTrans) {
        super(context, isTrans ? R.style.Loading_Dialog_trans : R.style.MyDialogStyle);
        init();
    }


    private void init() {
        setContentView(R.layout.common_dialog_loading_layout);
//        iv_route = (ImageView) findViewById(R.id.iv_route);
        detail_tv = (TextView) findViewById(R.id.detail_tv);
        tv_point = (TextView) findViewById(R.id.tv_point);
//        initAnim();

    }


    private void initAnim() {
// mAnim = new RotateAnimation(360, 0, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f);
//        mAnim = new RotateAnimation(0, 360, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f);
//        mAnim.setDuration(2000);
//        mAnim.setRepeatCount(Animation.INFINITE);
//        mAnim.setRepeatMode(Animation.RESTART);
//        mAnim.setStartTime(Animation.START_ON_FIRST_FRAME);
//        RotateAnimation rotateAnim=null;
//        if (mAnim == null) {
//            mAnim = (RotateAnimation) AnimationUtils.loadAnimation(context, R.anim.rotate);
//            //旋转一次不停顿
//            LinearInterpolator lir = new LinearInterpolator();
//            mAnim.setInterpolator(lir);
//        }

    }


    @Override
    public void show() {//在要用到的地方调用这个方法
//        iv_route.startAnimation(mAnim);
        //11111
//        handler.sendEmptyMessage(CHANGE_TITLE_WHAT);
        super.show();
    }


    @Override
    public void dismiss() {
//        mAnim.cancel();
        super.dismiss();
    }


    @Override
    public void setTitle(CharSequence title) {
        if (TextUtils.isEmpty(title)) {
            detail_tv.setText("正在处理");
        } else {
            detail_tv.setText(title);
        }
    }


    @Override
    public void setTitle(int titleId) {
        setTitle(getContext().getString(titleId));
    }


    public static void dismissDialog(LoadingDialog loadingDialog) {
        if (null == loadingDialog) {
            return;
        }
        loadingDialog.dismiss();
    }
}

